import { ITable } from '../types';
import { Table } from '../decorators';
import { RowHeader } from './row-header';
import { Row } from './row';
import { Config } from './config';
import { ColHeader } from './col-header';
import { TableBackGround } from './table-background';
import { Inject } from '../decorators/inject';
import { NExcel } from '../types';
import { Corner } from './corner';
import { Scroll } from './scroll';
import { TableEvent } from './table-event';
import { Hook } from './hook';
import { plugins } from '../pugins';
import { PluginManager } from './plugin-manager';
import { RenderTrigger } from './render-trigger';
import { View } from './view';
import { ExecuteRecord } from './execute-record';
@Table({
    cell: [],
    scroll: [],
    rowRender: null,
    colRender: null
})
export class ZTable implements ITable {
    protected ctx: CanvasRenderingContext2D;
    protected name: string;
    protected redraw: number = 0;
    protected _visible: boolean = false;
    private timer: number = null;
    set visible(val: boolean) {
        this.view.visible = val;
        this._visible = val;
    }
    get visible() {
        return this._visible;
    }
    constructor(
        protected hook: Hook,
        protected tableBg: TableBackGround,
        protected colHeader: ColHeader,
        protected rowHeader: RowHeader,
        protected config: Config,
        protected corner: Corner,
        protected scroll: Scroll,
        protected tableEvent: TableEvent,
        @Inject(NExcel.CanvasToken) protected canvasEle: HTMLCanvasElement,
        public pluginManager: PluginManager,
        protected renderTrigger: RenderTrigger,
        protected view: View,
        protected executeRecord: ExecuteRecord
    ) {
    }
    protected init() {
        for(let plugin of plugins) {
            this.pluginManager.load(plugin);
        }
        this.hook.afterTableInit.excute();
    }
    public getHook() {
        return this.hook;
    }
    public getCoreByName(name: string) {
        // @ts-ignore
        let instances = this.getAllIntance();
        for(let item of instances) {
            try {
                if((item.constructor.injectName as string).toLocaleLowerCase() === (name as string).toLocaleLowerCase()) {
                    return item;
                }
            } catch (error) {
                
            }
        }
        return null;
    }
    protected factory(row: {new():Row}): Row {
        return null;
    }
}